package com.ycsj.goldmedalnewconcept.cehua;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.widget.FrameLayout;

public class OpenNoTouchLayout  extends FrameLayout{

	private CloseableLayout dragLayout;
	
	private GestureDetector gestureDetector;

	public OpenNoTouchLayout(Context context, AttributeSet attrs,
			int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init();
	}

	public OpenNoTouchLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public OpenNoTouchLayout(Context context) {
		super(context);
		init();
	}
	
	
	private void init() {
		gestureDetector = new GestureDetector(getContext(), gestureListener); 
		
	}

	// 让外界指定是否需要拦截和消费事件
	
	public void setCloseableLayout(CloseableLayout dragLayout){
		this.dragLayout = dragLayout;
	}
	
	
	
	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		if(dragLayout!=null){
			return !dragLayout.isClose();
		}else{
			return false;
		}
		
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if(dragLayout!=null){
			if(gestureDetector.onTouchEvent(event)){
				dragLayout.close();
			}
			return !dragLayout.isClose();
		}else{
			return false;
		}
	}
	
	private OnGestureListener gestureListener = new  GestureDetector.SimpleOnGestureListener(){

		@Override
		public boolean onSingleTapUp(MotionEvent e) {
			return true;
		}
		
	};

}
